package com.cdivtc.management.controller;

import com.cdivtc.management.pojo.Result;
import com.cdivtc.management.pojo.StudentSelection;
import com.cdivtc.management.pojo.TeacherReleaseTask;
import com.cdivtc.management.service.StudentSelectionService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/studentSelection")
public class StudentSelectionController {

    @Autowired
    private StudentSelectionService studentSelectionService;

    @RequestMapping("/selStatus")
    public Result selStatus(String teaId) {
        System.out.println("StudentSelectionController line 27= " + teaId);
        if (teaId != null) {
            Integer integer = studentSelectionService.selStatus(teaId);
            return new Result().ok().addData(integer);
        }
        return new Result().error("查询为空");
    }

    @RequestMapping("/updStuGradeById")
    public Result updStuGradeById(String stuId, String grade) {
        if (stuId != null) {
            StudentSelection add = studentSelectionService.updStuGradeById(stuId, grade);
            if (add != null)
                return new Result().ok().addData(add);
            else
                return new Result().error("查询失败！！！");
        } else
            return new Result().error("数据为空");
    }

    @RequestMapping("/selStuGradeById")
    public Result selStuGradeById(String stuId) {
        if (stuId != null) {
            StudentSelection add = studentSelectionService.selStuGradeById(stuId);
            if (add != null)
                return new Result().ok().addData(add);
            else
                return new Result().error("查询失败！！！");
        } else
            return new Result().error("数据为空");
    }

    @RequestMapping("/add")
    public Result add(StudentSelection ss) {
        if (ss.getStuId() != null) {
            StudentSelection add = studentSelectionService.add(ss);
            if (add != null)
                return new Result().ok().addData(add);
            else
                return new Result().error("添加失败！！！");
        } else
            return new Result().error("数据为空");
    }

    @RequestMapping("/select")
    public Result select(String stuId) {
        if (stuId != null) {
            List<Map<String, Object>> select = studentSelectionService.select(stuId);
            if (select != null)
                return new Result().ok().addData(select);
            else
                return new Result().error("查询失败！！！");
        }
        return new Result().error("数据为空");
    }

    @RequestMapping("/delete")
    public Result delete(StudentSelection ss) {
        System.out.println("StudentSelectionController line 46= " + ss);
        if (ss.getId() != null) {
            StudentSelection delete = studentSelectionService.delete(ss);
            if (delete != null)
                return new Result().ok().addData(delete);
            else
                return new Result().error("删除失败！！！");
        }
        return new Result().error("删除为空");
    }

    @RequestMapping("/teaSel")
    public Result teaSel(String teaId) {
        System.out.println("StudentSelectionController line 59= " + teaId);
        if (teaId != null) {
            List<Map<String, Object>> list = studentSelectionService.selectByTeaId(teaId);
            if (list != null)
                return new Result().ok().addData(list);
            else
                return new Result().error("查询失败！！！");
        }
        return new Result().error("查询为空");
    }

    @RequestMapping("/teaSel2")
    public Result teaSel2(String teaId) {
        System.out.println("StudentSelectionController line 59= " + teaId);
        if (teaId != null) {
            List<Map<String, Object>> list = studentSelectionService.selectByTeaId2(teaId);
            if (list != null)
                return new Result().ok().addData(list);
            else
                return new Result().error("查询失败！！！");
        }
        return new Result().error("查询为空");
    }

    @RequestMapping("/selGrade")
    public Result selGrade() {
        HashSet<String> strings = studentSelectionService.selGrade();
        if (strings != null)
            return new Result().ok().addData(strings);
        else
            return new Result().error("查询失败！！！");
    }

    @RequestMapping("/update")
    public Result updata(UpdateStatus updateStatus) {
        System.out.println("StudentSelectionService line 145= " + updateStatus);
        if (updateStatus.getStatus() != null && updateStatus.getSsId() != null) {
            Boolean update = studentSelectionService.update(updateStatus);
            if (update)
                return new Result().ok().addData(update);
            else
                return new Result().error("查询失败！！！");
        } else {
            return new Result().error("查询失败！！！");
        }

    }

    @RequestMapping("/stuSelTopic")
    public Result stuSelTopic(String stuId) {
        System.out.println("StudentSelectionController line 100= " + stuId);
        if (stuId != null) {
            List<Map<String, Object>> list = studentSelectionService.stuSelTopic(stuId);
            if (list != null)
                return new Result().ok().addData(list);
            else
                return new Result().error("查询失败！！！");
        } else {
            return new Result().error("查询失败！！！");
        }

    }

    @RequestMapping("/stuSelTopicByTopicId")
    public Result stuSelTopicByTopicId(String topicId, String stuId) {
        System.out.println("StudentSelectionController line 100= " + topicId);
        if (topicId != null && stuId != null) {
            List<Map<String, Object>> list = studentSelectionService.stuSelTopicByTopicId(topicId, stuId);
            if (list != null)
                return new Result().ok().addData(list);
            else
                return new Result().error("查询失败！！！");
        } else {
            return new Result().error("查询失败！！！");
        }

    }

    @RequestMapping("/stuSelTopicById")
    public Result stuSelTopicById(String id, String stuId) {
        System.out.println("StudentSelectionController line 100= " + id);
        if (id != null && stuId != null) {
            Map<String, Object> map = studentSelectionService.stuSelTopicById(id, stuId);
            if (map != null)
                return new Result().ok().addData(map);
            else
                return new Result().error("查询失败！！！");
        } else {
            return new Result().error("查询失败！！！");
        }

    }

    @Data
    public class UpdateStatus {
        private List<String> ssId;
        private String status;
    }

}
